package com.lxh.lxhcrm.model.service;

import com.lxh.lxhcrm.model.dao.productManagement.InWareDao;
import com.lxh.lxhcrm.model.dao.productManagement.OutWareDao;
import com.lxh.lxhcrm.model.dao.productManagement.WareDetailDao;
import com.lxh.lxhcrm.model.mappers.emp.EmpMapper;
import com.lxh.lxhcrm.model.mappers.productManagement.WareMapper;
import com.lxh.lxhcrm.model.pojos.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WareService {
    @Resource
    WareMapper wareMapper;
    /*
     * 查询
     * */
    //出库表查询
    public List<OutWare> findOutWare(String searchText, Integer selectModel, Integer judge){return wareMapper.findOutWare(searchText,selectModel,judge);}
    //无分页查询出库
    public List<OutWare> allOutWare(){return wareMapper.allOutWare();}
    //入库表查询
    public List<InWare> findInWare(String searchText, Integer selectModel, Integer judge){return wareMapper.findInWare(searchText,selectModel,judge);}
    //无分页查询入库
    public List<InWare> allInWare(){return wareMapper.allInWare();}
    //查询所有交付计划，入库所需
    public List<DeliveryPlan> findDeliveryPlan(){return wareMapper.findDeliveryPlan();}
    @Resource
    EmpMapper empMapper;
    //查询此用户是否具备审核功能
    public boolean findDuty(Integer empId){
        boolean index = false;
        int item = empMapper.findDuty(empId);
        if(item == 1 || item == 5){
            index = true;
        }
        return index;
    }
    /*
     * 新增
     * */
    @Resource
    OutWareDao outWareDao;
    @Resource
    WareDetailDao wareDetailDao;
    //添加出库表
    public void addOutWare(OutWare outWare) {
        outWareDao.save(outWare);
        for (WareDetail wareDetail: outWare.getWareDetail()) {
            wareDetail.setOutWare(outWare);
            addWareDetail(wareDetail);
        }
    }
    //添加出库表详情表
    public void addWareDetail(WareDetail wareDetail) { wareDetailDao.save(wareDetail);}
    @Resource
    InWareDao inWareDao;
    //添加入库表
    public void addInWare(InWare inWare){
        inWareDao.save(inWare);
    }
    /*
     * 修改
     * */
    //修改出库表状态
    public void changeOutState(Integer judge,Integer outId){wareMapper.changeOutState(judge,outId);}
    //修改入库表状态
    public void changeInState(Integer judge,Integer inId){wareMapper.changeInState(judge,inId);}
    //出入库完成,修改产品数量
    public void changeProNum(Integer proDetailId,Integer wareNum,Integer proNum){wareMapper.changeProNum(proDetailId,wareNum,proNum);}
    //入库完成,修改交付计划状态
    public void changeDeliveryPlan(Integer isOut,Integer deliveryPlanId){wareMapper.changeDeliveryPlan(isOut,deliveryPlanId);}
}
